package com.silp.labs.cacticlient;

import java.util.ArrayList;

public class ProcessData {
	//public  TreeData[] treedata = new TreeData[100];
	//public int ntreelenght = 0;
	public static void ProcessDataHost(TreeData[] treedata,  int ntreelenght)
	{
		
	}
	public static int ProcessDataTree(String send_result,TreeData[] treedata,  int ntreelenght)
	{
		String[] lines =send_result.split("\\r?\\n");
		String tree = "";
		String host ="";
		String grp_name = "";
		String grp_id = "";
		//TreeData[] treedata = new TreeData[100];
		//int ntreelenght = 0;
		for (int i = 0; i < lines.length; i++) {
			//Toast.makeText(getApplicationContext(), lines[i], 100).show();
			String [] lines2=lines[i].split("/");
			for (int j = 0; j < lines2.length; j++) {
				if (j==0)
				{
					tree = lines2[j];
				}
				if (j ==1)
				{
					host = lines2[j];
				}
				if (j ==2)
				{
					String[] tmp = lines2[j].split("-");
					grp_id =tmp[0];
					grp_name = tmp[1];
				}
				
				
				if( ntreelenght == 0 || TreeData.CheckTreeExist(treedata, ntreelenght, tree) == false)
				{
					TreeData tr = new TreeData();
					
					tr.name = tree;
					Graph a = new Graph() ;
					a.id = grp_id;
					a.name = grp_name;
					Host h = new Host();
					h.hostname = host;
					h.AddGraph(a);
					tr.AddHost(h);
					treedata[ntreelenght] = tr;
					ntreelenght +=1;
						
				}
				else
				{
					int k = TreeData.GetTreeIndex(treedata, ntreelenght, tree);
					
					TreeData tr = treedata[k];
					
					
					if (host == "" || tr.CheckHostExist(host) == false)
					{
						Graph a = new Graph() ;
						a.id = grp_id;
						a.name = grp_name;
						Host h = new Host();
						h.hostname = host;
						h.AddGraph(a);
						tr.AddHost(h);
						//ntreelenght +=1;
					}
					else
					{
						int kh = tr.getHost(host);
						Host h = tr.host[kh];
						if (h.CheckGraphExist(grp_id)== false)
						{
							Graph a = new Graph() ;
							a.id = grp_id;
							a.name = grp_name;
							
							h.AddGraph(a);
						}
					}
				}

				//Toast.makeText(getApplicationContext(), tree + "-" + host +"-" + grp_id + "-" + grp_name, 100).show();

			}
		}
		return ntreelenght;
	}
	
}